package com.deep.spring.v27;

import org.junit.Assert;
import org.junit.jupiter.api.Test;
import org.springframework.core.NamedThreadLocal;

import java.util.HashSet;

/**
 * https://www.jianshu.com/p/807686414c11
 * https://www.jianshu.com/p/6384fff56954
 * https://www.cnblogs.com/xichji/p/11839811.html
 * https://www.freesion.com/article/75661111694/
 *
 * @author dell
 * @create 2022/7/15 8:42
 */
public class NamedThreadLocalTest {

    public static void main(String[] args) {
        ThreadLocal<String> localName = new ThreadLocal();
        localName.set("name1");
        String name = localName.get();
        System.out.println(name);
    }


    @Test
    public void test() {

        final ThreadLocal<Object> prototypesCurrentlyInCreation =
                new NamedThreadLocal<>("Prototype beans currently in creation");

        Assert.assertNull(prototypesCurrentlyInCreation.get());
        prototypesCurrentlyInCreation.set("abc");
        Assert.assertNotNull(prototypesCurrentlyInCreation.get());
        prototypesCurrentlyInCreation.set(new HashSet<>());
        Assert.assertNotNull(prototypesCurrentlyInCreation.get());
        prototypesCurrentlyInCreation.remove();
        Assert.assertNull(prototypesCurrentlyInCreation.get());
        System.out.println(prototypesCurrentlyInCreation.toString());
    }

}
